<template>
  <el-select style="width: 100%" v-model="name" clearable filterable placeholder="采购方"
             @change="selectCompany" value-key="id">
    <el-option
      v-for="item in companyList"
      :key="item.id"
      :label="item.name"
      :value="item">
    </el-option>
  </el-select>
</template>

<script>
import {list} from '@/api/customer'
import utils from '../../utils/utils.js'
export default{
  props:["name","type"],
  data(){
    return{
      query:{
        id:''
      },
      companyList:[],
      companyName:'',
      type:''
    }
  },
  // props:{
  //   queryTitle:{
  //     type:String,
  //     value:'请选择所属账户'
  //   },
  //   name:{
  //     type:String,
  //     value:''
  //   }
  // },
  watch:{
    name(newval,oldval){
      this.companyName=newval
    }

  },
  created() {
    var _this = this
    _this.companyName=this.name
    _this.type =this.type
      // console.log(this.type,'type')
    this.loadCompany()
  },
  methods:{
    selectCompany(data) {
      console.log(data)
      if(!utils.isNull(data)){
        this.query.id = data.id
        this.query.name = data.name
      }else{
        this.query.id = ''
        this.query.name = ''
      }
      this.$emit('queryCustomer',this.query)
    },
    loadCompany() {
      var _this = this
      _this.companyList =[]
      let params = new URLSearchParams();
      list(params).then(response => {
        console.log(response);
        console.log(this.type,'type')
        response.data.data.forEach(item =>{
          if(item.type == this.type){
            _this.companyList.push(item)
          }
        })
        // _this.companyList = response.data.data
      }).catch(error => {
        console.log('error!!')
      });
    }
  }
}
</script>

<style>
</style>

